package com.example.baserecyclerviewadapterdemo.base;

import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import com.example.baserecyclerviewadapterdemo.R;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

public abstract class BaseActivity extends AppCompatActivity {
    private String TAG = "";
    protected Toolbar toolbar = null;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TAG = getClass().getSimpleName();
        // 经测试在代码里直接声明透明状态栏更有效
        /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }*/

    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        if (hasToolbar()) {
            super.setContentView(R.layout.activity_base);
            toolbar = findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            FrameLayout frameLayout = findViewById(R.id.main_container);
            LayoutInflater.from(this).inflate(layoutResID,frameLayout,true);
        }else{
            super.setContentView(layoutResID);
        }
    }

    protected boolean hasToolbar(){
        return true;
    }

    protected Toolbar getParentToolbar(){
        if (hasToolbar()) {
            return toolbar;
        }else{
            throw new NullPointerException("未添加Toolbar控件");
        }
    }
}
